﻿Public Class frmAnalysisNoRelation
    Dim strsql As String
    Public DateServ As String
    Public income As String
    Public Rcpt_Money As String
    Public PTTYPE As String
    Dim mysql As New ClsSQLhelper
    
    Private Sub frmAnalysisNoRelation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim PttypeList As String = ""
            strsql = "select pttype from pttype where nhso_code = " & Me.PTTYPE
            Dim DT_PTTYPE As New DataTable
            DT_PTTYPE = mysql.GetMYSQLDataTable(strsql, "PTTYPE", True)

            PttypeList = "('" & DT_PTTYPE.Rows(0).Item("pttype").ToString & "'"
            If DT_PTTYPE.Rows.Count <> 1 Then
                For i = 1 To DT_PTTYPE.Rows.Count - 1
                    PttypeList = PttypeList & "'" & DT_PTTYPE.Rows(i).Item("pttype").ToString & "'"
                    If i <> DT_PTTYPE.Rows.Count - 1 Then
                        PttypeList = PttypeList & ","
                    End If
                Next
            End If
            PttypeList = PttypeList & ")"

            strsql = "select patient.fname,patient.lname,vn_stat.* from vn_stat left join patient on vn_stat.hn = patient.hn"
            strsql = strsql & " where ym= '" & Mid(DateServ, 1, 4) & "-" & Mid(DateServ, 5, 2) & "' and vstdate = '" & Mid(DateServ, 1, 4) & "-" & Mid(DateServ, 5, 2) & "-" & Mid(DateServ, 7, 2) & "' and income = '" & Me.income & "' and rcpt_money = '" & Me.Rcpt_Money & "'  and vn_stat.pttype in " & PttypeList & "  and (select person_id from person where patient_hn = patient.hn)  is null order by vn_stat.hn"
            Dim DT_VN_Stat As New DataTable
            DT_VN_Stat = mysql.GetMYSQLDataTable(strsql, "vn_stat", True)
            With DataGridView1
                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DT_VN_Stat

                If Me.DataGridView1.RowCount < 1 Then
                    MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("ดึงข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class